package com.lzhpo.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

@Configuration
public class ExecutorConfig implements SchedulingConfigurer {

	@Override
	public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
		ThreadPoolTaskScheduler taskScheduler = taskScheduler();
		scheduledTaskRegistrar.setTaskScheduler(taskScheduler);
	}

	/**
	 * 定时任务使用的线程池
	 * 
	 * @return
	 */
	@Bean(destroyMethod = "shutdown", name = "taskScheduler")
	public ThreadPoolTaskScheduler taskScheduler() {
		ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
		scheduler.setPoolSize(3);
		scheduler.setThreadNamePrefix("task-request-");
		scheduler.setAwaitTerminationSeconds(600);
		scheduler.setWaitForTasksToCompleteOnShutdown(true);
		return scheduler;
	}

}
